package com.smartum.mpr.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.smartum.mpr.model.County;

@Repository
public class CountyDao extends GenericDao<Long, County> {

	public List<County> getCountiesByStateId(Long stateID) {
		DetachedCriteria critteria = DetachedCriteria.forClass(County.class);
		critteria.addOrder(Order.asc("county"));
		critteria.createCriteria("state").add(Restrictions.eq("id", stateID));
		return hibernateTemplate.findByCriteria(critteria);
	}
	
	

	@Override
    public List<County> getList() {
		DetachedCriteria critteria = DetachedCriteria.forClass(County.class);
		critteria.addOrder(Order.asc("county"));
		return hibernateTemplate.findByCriteria(critteria);

    }



	public County getCountyByName(String countyName) {
		DetachedCriteria critteria = DetachedCriteria.forClass(County.class);
		critteria.add(Restrictions.eq("county", countyName));
		List<County> counties = hibernateTemplate.findByCriteria(critteria);
		if (counties.size() == 1) {
			return counties.get(0);
		} else {
			return null;
		}
	}
	
	
	
	@Override
	protected Class<County> getEntityClass() {
		return County.class;
	}

}
